package com.redfootdev.horseskills;

import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Player;

public class Agility {

	public int horseJumped(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider, float jump) {
		// first decide if there is going to be any damage.
		
		
		// look up the horse and player attributes.
		Skill agility = hdb.getAgility(horse);
		Skill horsemanship = pdb.getHorsemanship(rider);
		// calculate the XP gain for strength.
		int xpGainAgility = (int)(jump*20*(1+horsemanship.getLevel()/100));
		// apply XP to strength Skill
		if(agility.addXP(xpGainAgility)) {
			rider.sendMessage(ChatColor.AQUA + "Your Agility level is now " + agility.getLevel() + ".");
		}
		hdb.setAgility(horse, agility);
		
		return xpGainAgility;
		
		
	}	
	
	public int horseWasRiddenForTime(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider, int time) {
		Skill agility = hdb.getAgility(horse);
		// calculate the XP gain for strength.
		int xpGainAgility = (int)(time/3);
		// apply XP to strength Skill
		if(agility.addXP(xpGainAgility)) {
			rider.sendMessage(ChatColor.AQUA + "Your Agility level is now " + agility.getLevel() + ".");
		}
		hdb.setAgility(horse, agility);
		
		return xpGainAgility;
	}
	
	public int horseHasFallen(HorseDatabase hdb, PlayerDatabase pdb, Entity horse, Player rider, double damage) {
		
		Skill agility = hdb.getAgility(horse);
		Skill horsemanship = pdb.getHorsemanship(rider);
		// calculate the XP gain for strength.
		int xpGainAgility = (int)(damage*30*(1+horsemanship.getLevel()/100));
		// apply XP to strength Skill
		if(agility.addXP(xpGainAgility)) {
			rider.sendMessage(ChatColor.AQUA + "Your Agility level is now " + agility.getLevel() + ".");
		}
		hdb.setAgility(horse, agility);
		
		return xpGainAgility;
		
	}
	
	public String toString(HorseDatabase hdb, PlayerDatabase pdb, Horse horse, Player rider) {

		Skill agility = hdb.getAgility(horse);


		int level = agility.getLevel();
		int xp = agility.getXP();
		double jump = (horse.getJumpStrength());
		
		String stats = ChatColor.AQUA + "Agility Level: " + level + "\nExperience: " + xp + "\nJump Strength: " + jump;
		return stats;
	}
	public double fallDamageReduction(HorseDatabase hdb, Horse horse, double fallDamage) {
		Skill agility = hdb.getAgility(horse);
		int level = agility.getLevel();
		
		return fallDamage-fallDamage*(level/200);
	}
}
